//
//  BusinessActivity_Detail.m
//  HappyStore
//
//  Created by 点点充 on 16/1/19.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "BusinessActivity_Detail.h"

@interface BusinessActivity_Detail ()
{
    NSDictionary *dicData;
    //顶部图片
    NSArray *TopPhotos;
    
    UITextField *tfPingLun;//评论
    UIButton *btnTiJiao;
    UIButton *btnJuBao;
    
    NSMutableArray *commentsList;
    
    UIButton *btnZan;
    
    LoveData *_loveData;
    
    BOOL isRemove;
    
    NSInteger paggge;
    
}
@end

@implementation BusinessActivity_Detail

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
    if (!isRemove) {
        isRemove = YES;
        [_loveData removeObserver:self forKeyPath:@"focusNumber" context:@"1"];
        [_loveData removeObserver:self forKeyPath:@"isfocus" context:@"2"];
    }
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16.f],NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    
    self.tabBarController.tabBar.hidden = YES;
    isRemove = YES;
    
    [self startNetWork];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"project_detail_share"] style:UIBarButtonItemStylePlain target:self action:@selector(btnCickRight)];
    self.navigationItem.rightBarButtonItem = rightBar;
    
    paggge = 1;
    _mainTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        paggge += 1;
        
        [self getMorePingLun];
    }];
    
    _mainTableView.mj_footer.hidden = YES;
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
}

#pragma mark - 分享
- (void)btnCickRight
{
    [self showErrorWithTitle:@"暂未开放!" autoCloseTime:2];

}


- (void)startNetWork
{
    [self showRoundProgressWithTitle:@"加载中..."];
    
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    //    userId=当前登录用户id&projectId=项目id
    [muDicParameters setObject:_activityId forKey:@"activityId"];
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    }
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"activityDetail_app_activity.im"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            dicData = [dicInfo objectForKey:@"data"];
            
            if (_loveData == nil) {
                _loveData = [[LoveData alloc] init];
            }
            [_loveData setValue:[NSString stringWithFormat:@"%@",dicData[@"focusNumber"]] forKey:@"focusNumber"];
            [_loveData setValue:dicData[@"isfocus"] forKey:@"isfocus"];
            
            if ([USER_DEFAULTS objectForKey:@"userid"] != nil) {
                [_loveData addObserver:self forKeyPath:@"focusNumber" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:@"1"];
                [_loveData addObserver:self forKeyPath:@"isfocus" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:@"2"];
                isRemove = NO;
            }
            
            if ([dicData[@"isSignUp"] isEqualToString:@"是"]) {
                self.btnBaoMing.userInteractionEnabled = NO;
                [self.btnBaoMing setTitle:@"已报名" forState:UIControlStateNormal];
            }else {
                self.btnBaoMing.userInteractionEnabled = YES;
                [self.btnBaoMing setTitle:@"我要报名" forState:UIControlStateNormal];
            }
            
            //顶部图片
            TopPhotos = dicData[@"photos"];
            
            
            commentsList = [NSMutableArray arrayWithArray:dicData[@"commentsList"]];
            
            if (commentsList.count == 10) {
                _mainTableView.mj_footer.hidden = NO;
            }else {
                _mainTableView.mj_footer.hidden = YES;
            }
            
            [_mainTableView reloadData];
            
            [self hideBubble];
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        [_mainTableView.mj_footer endRefreshing];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [_mainTableView.mj_footer endRefreshing];

        [self showSingleIconBubble:error.localizedDescription];

    }];
}


#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4+commentsList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            return 150;
        }
            break;
        case 1:
        {
            return 124;
        }
            break;
        case 2://内容
        {
            CGSize size1 = CGSizeMake(0, 0);
            if (dicData[@"description"] == [NSNull null] || [dicData[@"description"] isEqualToString:@"null"]) {
                
                return 8+158*TopPhotos.count;
            }else {
                size1 = [LLJLabelHeight UIlabelGetFont:16.f sizeWidth:300 strNeirong:dicData[@"description"]];
                return size1.height+8+158*TopPhotos.count;
            }
        }
            break;
        case 3://评论
        {
            return 70;
        }
            break;
        default:
        {
            if (commentsList.count != 0) {
                CGSize size1 = [LLJLabelHeight UIlabelGetFont:14.f sizeWidth:247 strNeirong:[NSString stringWithFormat:@"%@",commentsList[indexPath.row-4][@"content"]]];
                return 58+size1.height+14;
            }else
            {
                return 90;
            }
            
        }
            break;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellTopXT = @"cellTopXT";//顶部
    static NSString *cellInfo = @"cellInfo";//个人信息
    static NSString *cellContent = @"cellContent";//内容
    static NSString *cellpinglun = @"cellpinglun";//评论
    static NSString *cellpinglunDetail = @"cellpinglunDetail";//评论详情
    
    UITableViewCell *cell;
    
    switch (indexPath.row) {
        case 0:
        {
            cell = [tableView dequeueReusableCellWithIdentifier:cellTopXT forIndexPath:indexPath];
            UIImageView *imgView = [cell viewWithTag:10];
            [imgView sd_setImageWithURL:[NSURL URLWithString:TopPhotos[0]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
            
            btnZan = [cell viewWithTag:20];
            btnZan.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f];
            
            btnZan.layer.masksToBounds = YES;
            btnZan.layer.cornerRadius = 8.0f;
            
            [btnZan addTarget:self action:@selector(btnClickZan) forControlEvents:UIControlEventTouchUpInside];
            [btnZan setTitle:[_loveData valueForKey:@"focusNumber"] forState:UIControlStateNormal];
            
            if ([[_loveData valueForKey:@"isfocus"] isEqualToString:@"否"]) {
                [btnZan setImage:[UIImage imageNamed:@"project_detail_taoxin_normal"] forState:UIControlStateNormal];
            }else {
                [btnZan setImage:[UIImage imageNamed:@"project_detail_taoxin_pressed"] forState:UIControlStateNormal];
            }
        }
            break;
        case 1:
        {
            cell = [tableView dequeueReusableCellWithIdentifier:cellInfo forIndexPath:indexPath];
            
//            UIView *viewBack = [cell viewWithTag:50];
//            viewBack.layer.masksToBounds = YES;
//            viewBack.layer.borderColor = [UIColor colorWithWhite:0.8 alpha:1.0f].CGColor;
//            viewBack.layer.borderWidth = 0.5f;
            
            //15.16.17
            UIImageView *imgHeader = [cell viewWithTag:15];
            [imgHeader sd_setImageWithURL:[NSURL URLWithString:dicData[@"headPhoto"]] placeholderImage:[UIImage imageNamed:@"project_detail_heder_normal"]];
            imgHeader.layer.masksToBounds = YES;
            imgHeader.layer.cornerRadius = 23.f;
            
            UILabel *labUserName = [cell viewWithTag:16];
            if (dicData[@"username"] == [NSNull null] || [dicData[@"username"] isEqualToString:@"null"]) {
                labUserName.text = dicData[@"account"];
            }else {
                labUserName.text = dicData[@"username"];
            }
            
            //进用户详情
            UIButton *btnHeader = [cell viewWithTag:17];
            [btnHeader addTarget:self action:@selector(btnClickToUser) forControlEvents:UIControlEventTouchUpInside];
            
            
            UILabel *labTitle = [cell viewWithTag:21];
            labTitle.text = dicData[@"title"];
            
            UILabel *labPrice = [cell viewWithTag:22];
            labPrice.text = [CustomExcetion comperNumber:dicData[@"investment"]];
            
            UILabel *labAddress = [cell viewWithTag:23];
            labAddress.text = dicData[@"address"];
            
            //createtime
            UILabel *labDate = [cell viewWithTag:24];
            NSDate *date = [CustomExcetion dateFromString:dicData[@"createtime"]];
            labDate.text = [CustomExcetion prettyDateWithReference:date];
            
            
            //活动时间25
            UILabel *labActivityDate = [cell viewWithTag:25];
            
            labActivityDate.text = [NSString stringWithFormat:@"%@－%@",[self stringFromDate:[self dateFromString:dicData[@"starttime"]]],[self stringFromDate:[self dateFromString:dicData[@"endtime"]]]];
            
            //报名人数26
            UILabel *labPeopleNum = [cell viewWithTag:26];
            labPeopleNum.text = [NSString stringWithFormat:@"%@人报名",dicData[@"signupNumber"]];
            
            
            
        }
            break;
        case 2://内容
        {
            cell = [tableView dequeueReusableCellWithIdentifier:cellContent forIndexPath:indexPath];
            
            CGSize size1 = CGSizeMake(0, 8);
            if (dicData[@"description"] == [NSNull null] || [dicData[@"description"] isEqualToString:@"null"]) {
                for (int i = 0; i<TopPhotos.count; i++) {
                    UIImageView *img = [[UIImageView alloc] initWithFrame:(CGRect){10,(size1.height)+158*i,300,150}];
                    [img sd_setImageWithURL:[NSURL URLWithString:TopPhotos[i]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
                    [cell addSubview:img];
                }
                
            }else {
                UILabel *labContent = [[UILabel alloc] init];
                size1 = [LLJLabelHeight UIlabelGetFont:16.f sizeWidth:300 strNeirong:dicData[@"description"]];
                labContent.frame = (CGRect){10,8,300,size1.height};
                labContent.text = dicData[@"description"];
                labContent.font = [UIFont systemFontOfSize:16.f];
                labContent.textColor = [UIColor colorWithRed:89/255.0f green:87/255.0f blue:87/255.0f alpha:1.0f];
                labContent.numberOfLines = 0;
                [cell addSubview:labContent];
                
                for (int i = 0; i<TopPhotos.count; i++) {
                    UIImageView *img = [[UIImageView alloc] initWithFrame:(CGRect){10,(labContent.frame.origin.y + labContent.frame.size.height + 8)+158*i,300,150}];
                    [img sd_setImageWithURL:[NSURL URLWithString:TopPhotos[i]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
                    [cell addSubview:img];
                }
                
            }
        }
            break;
        case 3://评论
        {
            cell = [tableView dequeueReusableCellWithIdentifier:cellpinglun forIndexPath:indexPath];
            //10
            tfPingLun = [cell viewWithTag:10];
            btnTiJiao = [cell viewWithTag:11];
            btnTiJiao.layer.masksToBounds = YES;
            btnTiJiao.layer.cornerRadius = 5.0f;
            [btnTiJiao addTarget:self action:@selector(btnClickTijiaoPL) forControlEvents:UIControlEventTouchUpInside];
            btnJuBao = [cell viewWithTag:12];
            [btnJuBao addTarget:self action:@selector(btnClickJuBao) forControlEvents:UIControlEventTouchUpInside];
            
        }
            break;
        default://评论详情
        {
            /*
             commentAccount = cxs123;
             commentId = 2;
             commentUserId = 9;
             content = 1234;
             createTime = "2016-01-15 17:20:29.827";
             headPhoto = "http://123.56.77.28:8080/lensum/image_public.htm?path=9_headLogo_1.gif";
             */
            cell = [tableView dequeueReusableCellWithIdentifier:cellpinglunDetail forIndexPath:indexPath];
            
            UIButton *btnHeader = [cell viewWithTag:10];
            [btnHeader sd_setImageWithURL:[NSURL URLWithString:commentsList[indexPath.row-4][@"headPhoto"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"project_detail_heder_normal"]];
            btnHeader.layer.masksToBounds = YES;
            btnHeader.layer.cornerRadius = 18.f;
            cell.contentView.tag = indexPath.row-4 +100;
            [btnHeader addTarget:self action:@selector(btnClick111:) forControlEvents:UIControlEventTouchUpInside];
            
            
            
            UIButton *btnUserName = [cell viewWithTag:11];
            [btnUserName setTitle:commentsList[indexPath.row-4][@"commentUsername"] forState:UIControlStateNormal];
            
            UILabel *labDate = [cell viewWithTag:12];
            NSDate *date = [CustomExcetion dateFromString:commentsList[indexPath.row-4][@"createTime"]];
            labDate.text = [CustomExcetion prettyDateWithReference:date];
            
            
            CGSize size1 = [LLJLabelHeight UIlabelGetFont:14.f sizeWidth:247 strNeirong:[NSString stringWithFormat:@"%@",commentsList[indexPath.row-4][@"content"]]];
            UILabel *labContent = [cell viewWithTag:13];
            labContent.translatesAutoresizingMaskIntoConstraints = YES;
            CGRect rect1 = labContent.frame;
            rect1.size.height = size1.height;
            labContent.frame = rect1;
            labContent.text = [NSString stringWithFormat:@"%@",commentsList[indexPath.row-4][@"content"]];
            
            //13
            UILabel *labFenGe = [cell viewWithTag:14];
            labFenGe.translatesAutoresizingMaskIntoConstraints = YES;
            CGRect rect2 = labFenGe.frame;
            rect2.origin.y = labContent.frame.origin.y + labContent.frame.size.height+13;
            labFenGe.frame = rect2;
            
            
            
            
        }
            break;
    }
    
    
    
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    
    
}

/**
 *  @author LLJ, 16-01-19 11:01:31
 *
 *  点赞
 */
- (void)btnClickZan
{
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        [self showRoundProgressWithTitle:@"请稍后..."];
        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        //token=验证用户&userId=用户id&resId=资源id&resType=资源类型（1-项目 2-活动 3-服务 4-资金 5-招聘求职）
        [muDicParameters setObject:_activityId forKey:@"resId"];//资源id
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        [muDicParameters setObject:@"2" forKey:@"resType"];
        NSString *strURl = @"";
        if ([[_loveData valueForKey:@"isfocus"] isEqualToString:@"否"]) {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusResources_app_action.im.lensum"];
        }else {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusResourcesCancel_app_action.im.lensum"];
        }
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//            NSLog(@"%@",dicInfo);
            
            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                NSInteger focus = [[_loveData valueForKey:@"focusNumber"] integerValue];
                if ([[_loveData valueForKey:@"isfocus"] isEqualToString:@"否"]) {
                    focus += 1;
                    [_loveData setValue:@"是" forKey:@"isfocus"];
                }else {
                    focus -= 1;
                    [_loveData setValue:@"否" forKey:@"isfocus"];
                    
                }
                [_loveData setValue:[NSString stringWithFormat:@"%ld",focus] forKey:@"focusNumber"];

                [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
            }else {

                [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self showSingleIconBubble:error.localizedDescription];

        }];
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
}


-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if([keyPath isEqualToString:@"focusNumber"])
    {
        [btnZan setTitle:[_loveData valueForKey:@"focusNumber"] forState:UIControlStateNormal];
        
    }else if ([keyPath isEqualToString:@"isfocus"])
    {
        if ([[_loveData valueForKey:@"isfocus"] isEqualToString:@"否"]) {
            [btnZan setImage:[UIImage imageNamed:@"project_detail_taoxin_normal"] forState:UIControlStateNormal];
        }else {
            [btnZan setImage:[UIImage imageNamed:@"project_detail_taoxin_pressed"] forState:UIControlStateNormal];
        }
    }
}

/**
 *  @author LLJ, 16-01-19 12:01:50
 *
 *  提交评论
 */
- (void)btnClickTijiaoPL
{
    if (tfPingLun.text.length != 0) {
        if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
            [tfPingLun becomeFirstResponder];
            [self showRoundProgressWithTitle:@"请稍后..."];
            
            NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
            //token=验证&resId=资源id&content=内容&userId=用户id&userName=用户名
            [muDicParameters setObject:_activityId forKey:@"resId"];//资源id
            [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
            [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
            [muDicParameters setObject:tfPingLun.text forKey:@"content"];
            [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"account"] forKey:@"userName"];
            
            NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"commentActivity_app_action.im.lensum"];
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                
            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                
                NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];

//                NSLog(@"%@",dicInfo);
                if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                    commentsList = [NSMutableArray arrayWithArray:[dicInfo objectForKey:@"data"]];
                    
                    tfPingLun.text = @"";
                    
                    if (commentsList.count == 10) {
                        _mainTableView.mj_footer.hidden = NO;
                    }else {
                        _mainTableView.mj_footer.hidden = YES;
                    }
                    
                    [_mainTableView reloadData];

                    [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
                }else {

                    [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                }
                

            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                [self showSingleIconBubble:error.localizedDescription];

            }];
        }else {
            //登录
            UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
            [self presentViewController:loginNAV animated:YES completion:nil];
        }
    }
}

/**
 *  @author LLJ, 16-01-19 12:01:09
 *
 *  举报
 */
- (void)btnClickJuBao
{
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"举报" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
        alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        UITextField *nameField = [alert textFieldAtIndex:0];
        nameField.placeholder = @"请输入举报内容";
        
        UITextField *urlField = [alert textFieldAtIndex:1];
        urlField.placeholder = @"请输入联系电话";
        urlField.secureTextEntry = NO;
        urlField.keyboardType = UIKeyboardTypePhonePad;
        //        urlField.text = [USER_DEFAULTS objectForKey:@"phone"];
        
        [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
            if(buttonIndex == 1){
                UITextField *tf=[alert textFieldAtIndex:0];
                UITextField *tfPhone = [alert textFieldAtIndex:1];
                if (tf.text.length > 0 && tfPhone.text.length > 0) {
                    
                    [self showRoundProgressWithTitle:@"请稍后..."];
                    
                    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                    //token=验证用户&userId=用户id&resId=资源id&resType=资源类型（1-项目 2-活动 3-服务 4-资金 5-简历'）&contact=联系号码&why=举报原因
                    [muDicParameters setObject:_activityId forKey:@"resId"];//资源id
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                    [muDicParameters setObject:@"2" forKey:@"resType"];//资源类型
                    [muDicParameters setObject:tf.text forKey:@"why"];
                    [muDicParameters setObject:tfPhone.text forKey:@"contact"];//联系号码
                    
                    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"complaintsResources_app_action.im.lensum"];
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                        
                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        
                        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//                        NSLog(@"%@",dicInfo);

                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                            [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
                        }else {
                            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                            
                        }
                        
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                       [self showSingleIconBubble:error.localizedDescription];

                    }];
                }
            }
        }];
        
        
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  @author LLJ, 16-01-19 12:01:59
 *
 *  我要报名
 *
 *  @param sender <#sender description#>
 */
- (IBAction)btnClickPingTaiYinJian:(id)sender
{
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"报名" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
        alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
        UITextField *tfphoto = [alert textFieldAtIndex:0];
        tfphoto.placeholder = @"请输入联系电话";
        tfphoto.keyboardType = UIKeyboardTypePhonePad;
        
        UITextField *urlField = [alert textFieldAtIndex:1];
        urlField.placeholder = @"说点什么吧";
        urlField.secureTextEntry = NO;
        
        
        [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
            if(buttonIndex == 1){
                UITextField *tfPhone=[alert textFieldAtIndex:0];
                UITextField *tfContent = [alert textFieldAtIndex:1];
                if (tfPhone.text.length > 0) {
                    [self showRoundProgressWithTitle:@"请稍后..."];
                    
                    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                    [muDicParameters setObject:_activityId forKey:@"activityId"];//资源id
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                    [muDicParameters setObject:tfPhone.text forKey:@"phone"];
                    [muDicParameters setObject:tfContent.text forKey:@"content"];
                    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"signUpActivity_app_activity.im.lensum"];
                    
                    
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                        
                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        
                        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//                        NSLog(@"%@",dicInfo);

                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                            [self.btnBaoMing setTitle:@"已报名" forState:UIControlStateNormal];
                            self.btnBaoMing.userInteractionEnabled = NO;
                            [self showRightWithTitle:@"报名成功,请按时参加!" autoCloseTime:2];
                        }else {
                            self.btnBaoMing.userInteractionEnabled = YES;

                            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                        }
                        
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                        [self showSingleIconBubble:error.localizedDescription];

                    }];
                }
            }
        }];
        
        
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
    
    
    
    
    
//    [SVProgressHUD showSuccessWithStatus:@"暂未开放此功能!"];
//    [SVProgressHUD dismissafterDelay:kHideHudDelay];
}



#pragma mark - 获取更多评论
- (void)getMorePingLun
{
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    //page=页码&projectId=项目id
    [muDicParameters setObject:_activityId forKey:@"projectId"];
    [muDicParameters setObject:[NSString stringWithFormat:@"%ld",paggge] forKey:@"page"];
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"manyComentActivity_app_activity.im"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            NSArray *aryInff = [dicInfo objectForKey:@"data"][@"record"];
            
            for (int i = 0; i<aryInff.count; i++) {
                [commentsList addObject:aryInff[i]];
            }
            
            if (aryInff.count == 10) {
                _mainTableView.mj_footer.hidden = NO;
            }else {
                _mainTableView.mj_footer.hidden = YES;
            }
            
            
            
            [_mainTableView reloadData];
            
            [self hideBubble];
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        [_mainTableView.mj_footer endRefreshing];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [_mainTableView.mj_footer endRefreshing];

        [self showSingleIconBubble:error.localizedDescription];

    }];
}

- (NSDate *)dateFromString:(NSString *)dateString
{
    NSTimeZone *currentDateTimeZone = [NSTimeZone defaultTimeZone];
    NSDateFormatter *currentDateFormat = [[NSDateFormatter alloc]init];
    [currentDateFormat setTimeZone:currentDateTimeZone];
    [currentDateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
    
    NSDate *destDate = [currentDateFormat dateFromString:dateString];
    
    return destDate;
    
}

- (NSString *)stringFromDate:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息。
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    NSString *destDateString = [dateFormatter stringFromDate:date];
    
    return destDateString;
    
}

#pragma mark -进用户详情
- (void)btnClickToUser
{
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    
    switch ([dicData[@"userType"] integerValue]) {
        case 1:
        {
            ThirdPerson_Person *person = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdPerson"];
            person.strUserId = dicData[@"userId"];
            person.strUserType = @"1";//个人
            person.strUserName = [NSString stringWithFormat:@"%@的详情",dicData[@"username"]];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
        case 2:
        {
            ThirdPerson_Company *person = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdCompany"];
            person.strUserId = dicData[@"userId"];
            person.strUserType = @"2";//企业
            person.strUserName = [NSString stringWithFormat:@"%@的详情",dicData[@"username"]];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
        case 3:
        {
            ThirdPerson_Government *person = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdGovernmet"];
            person.strUserId = dicData[@"userId"];
            person.strUserType = @"3";//企业
            person.strUserName = [NSString stringWithFormat:@"%@的详情",dicData[@"username"]];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
    }
    
}


- (void)btnClick111:(UIButton *)sender
{
    NSInteger indexx = sender.superview.tag - 100;
    NSLog(@"%ld",indexx);
    
    
    
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    switch ([commentsList[indexx][@"userType"] integerValue]) {
        case 1:
        {
            ThirdPerson_Person *person = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdPerson"];
            person.strUserId = commentsList[indexx][@"commentUserId"];
            person.strUserType = @"1";//个人
            person.strUserName = [NSString stringWithFormat:@"%@的详情",commentsList[indexx][@"commentUsername"]];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
        case 2:
        {
            ThirdPerson_Company *person = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdCompany"];
            person.strUserId = commentsList[indexx][@"commentUserId"];
            person.strUserType = @"2";//企业
            person.strUserName = [NSString stringWithFormat:@"%@的详情",commentsList[indexx][@"commentUsername"]];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
        case 3:
        {
            ThirdPerson_Government *person = [self.storyboard instantiateViewControllerWithIdentifier:@"thirdGovernmet"];
            person.strUserId = commentsList[indexx][@"commentUserId"];
            person.strUserType = @"3";//企业
            person.strUserName = [NSString stringWithFormat:@"%@的详情",commentsList[indexx][@"commentUsername"]];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
    }
}


@end
